<template>
  <div class="app-container">
    <el-row type="flex" align="center" :gutter="20">
      <el-form class="filterData-block" label-position="left" :inline="true" label-width="auto">
        <el-form-item label="年龄:">
          <el-cascader
            v-model="filterData.age"
            clearable
            placeholder="选择年龄"
            :options="placeTypeOption4"
            size="small"
            :props="{value:'name',label:'name'}"
            filterDataable
          ></el-cascader>
        </el-form-item>
        <el-form-item label="性别:">
          <el-cascader
           v-model="filterData.sex"
            clearable
            placeholder="选择性别"
            :options="placeTypeOption"
            size="small"
            :props="{value:'name',label:'name'}"
            filterDataable
          ></el-cascader>
        </el-form-item>
        <el-form-item label="学历:">
          <el-cascader
            v-model="filterData.education"
            clearable
            placeholder="选择学历"
            :options="placeTypeOption1"
            size="small"
            :props="{value:'name',label:'name'}"
            filterDataable
          ></el-cascader>
        </el-form-item>
        <el-form-item label="户籍:">
          <el-cascader
            v-model="filterData.domicile"
            clearable
            placeholder="选择户籍"
            :options="placeTypeOption2"
            size="small"
            :props="{value:'name',label:'name'}"
            filterDataable
          ></el-cascader>
        </el-form-item>
        <el-form-item label="工种:">
          <el-cascader
            v-model="filterData.workIndustry"
            clearable
            placeholder="选择工种"
            :options="placeTypeOption3"
            size="small"
            :props="{value:'name',label:'name'}"
            filterDataable
          ></el-cascader>
        </el-form-item>
        <el-form-item>
          <el-button size="small" icon="el-icon-search" type="primary" @click="reset">重置</el-button>
        </el-form-item>
        <el-form-item>
          <el-button size="small" icon="el-icon-search" type="primary" @click="refreshTable">搜索</el-button>
        </el-form-item>
        <el-form-item>
          <el-button size="small" icon="el-icon-download" type="primary" @click="exportRecord">导出</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-row style="margin-top: 20px">
      <el-table v-loading="tableConf.loading" :stripe="true" :border="true" :data="tableData">
        <el-table-column align="center" prop="id" label="ID"/>
        <el-table-column align="center" label="家乡所以在地是" width="240px">
          <template  slot-scope="{row}">
            <div>{{row.provinceIdText}}-{{row.cityIdText}}-{{row.areaIdText}}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="domicile" label="户口类型"/>
        <el-table-column align="center" prop="sex" label="性别"/>
        <el-table-column align="center" prop="age" label="培训年龄"/>
        <el-table-column align="center" prop="education" label="学历"/>
        <el-table-column align="center" prop="skillLevel" label="技能等级"/>
        <el-table-column align="center" prop="difficulty" label="是否建档立卡贫困户"/>
        <el-table-column align="center" prop="workTime" label="外出务工时间"/>
        <el-table-column align="center" prop="isFamily" label="是否和家人一起"/>
        <el-table-column align="center" prop="address" label="当前所在地"/>
        <el-table-column align="center" prop="workFeel" label="当前所在地感受"/>
        <el-table-column align="center" prop="income" label="全部劳动收"/>
        <el-table-column align="center" prop="incomeReduce" label="相比2022年收入"/>
        <el-table-column align="center" prop="addressType" label="当前所在地"/>
        <el-table-column align="center" prop="workState" label="工作情况"/>
        <el-table-column align="center" prop="goOut" label="2024年是否外出务工"/>
        <el-table-column align="center" prop="workIndustry" label="工种"/>
        <el-table-column align="center" prop="reconmendation" label="建议"/>
      </el-table>
    </el-row>
  </div>
</template>

<script>
import TrainCodeDetail from '@/components/TrainCode/Detail'
import {getList,exportEnterpriseApi} from '@/api/questionnaire'
import { createFile } from '@/utils/utils'

export default {
  components: { TrainCodeDetail },
  data() {
    return {
      placeTypeOption:[
        {
          id:1,
          name:'①男'
        },
        {
          id:2,
          name:'②女'
        }
      ],
      placeTypeOption1:[
        {
          id: 1,
          name: '①小学及以下'
        }, {
          id: 2,
          name: '②初中'
        }, {
          id: 3,
          name: '③高中'
        }, {
          id: 4,
          name: '④中专、职高、技校'
        }, {
          id: 5,
          name: '⑤大专、高职、技师院校'
        }, {
          id: 6,
          name: '⑥本科及以上'
        },
      ],
      placeTypeOption2:[
        {
          id: 1,
          name: '①农村'
        }, {
          id: 2,
          name: '②城镇'
        },
      ],
      placeTypeOption3:[
        {
          id: 1,
          name: '①建筑业'
        }, {
          id: 2,
          name: '②制造业'
        }, {
          id: 3,
          name: '③采掘业'
        },
        {
          id: 4,
          name: '④建材业'
        },
        {
          id: 5,
          name: '⑤服务业'
        },
        {
          id: 6,
          name: '⑥其他'
        },
      ],
      placeTypeOption4:[
        {
          id: 1,
          name: '①16-20岁'
        }, {
          id: 2,
          name: '②21-30岁'
        }, {
          id: 3,
          name: '③31-40岁'
        }, {
          id: 4,
          name: '④41-50岁'
        }, {
          id: 5,
          name: '⑤51-60岁'
        }, {
          id: 6,
          name: '⑥60岁以上'
        },
      ],
      tableData: [],
      tableConf: {
        page: 1,
        sizes: [10, 20, 50, 100],
        total: 0,
        size: 10,
        loading: false
      },
      visible: {//控制弹窗显示
        0: false
      },
      detailId: null,
      keyword: '',//关键字查询
      filterData: {
        age: [],
        sex: [],
        education: [],
        domicile: [],
        workIndustry: {},
      },
      placeTypeLoading: true,
      trainTypeOption: []
    }
  },
  mounted() {
    this.getTableList()
  },
  methods: {
    downloadCode(url) {
      window.open(url)
    },
    openRecord(sid) {
      //新标签页打开列表
      this.$router.push({
        name: 'TrainCustomer',
        query: {
          sid: sid
        }
      })
    },
    //打开添加/编辑页
    openDetail(id = null) {
      this.detailId = id
      this.visible[0] = true
    },
    //关闭指定弹窗并刷新页面
    closeDialog(index) {
      this.visible[index] = false
      this.getTableList()
    },
    // 每页显示数量change
    handleSizeChange(e) {
      this.tableConf.size = e
      this.getTableList()
    },
    // 当前页change
    handleCurrentChange(e) {
      this.tableConf.page = e
      this.getTableList()
    },
    //获取列表
    getTableList() {
      this.tableConf.loading = true
      const age = this.filterData.age.length === 0 ? '' : this.filterData.age[0];
      const sex = this.filterData.sex.length === 0 ? '' : this.filterData.sex[0];
      const education = this.filterData.education.length === 0 ? '': this.filterData.education[0];
      const domicile = this.filterData.domicile.length === 0 ? '' : this.filterData.domicile[0];
      const workIndustry = this.filterData.workIndustry.length === 0 ? '' : this.filterData.workIndustry[0];
      getList({
        page: this.tableConf.page,
        limit: this.tableConf.size,
        age: age,
        sex: sex,
        education: education,
        domicile: domicile,
        workIndustry: workIndustry,
      }).then((res) => {
        this.tableData = res.list
        this.tableConf.total = res.count
      }).finally(() => {
        this.tableConf.loading = false
      })
    },
    exportRecord(){
      const age = this.filterData.age.length === 0 ? '' : this.filterData.age[0];
      const sex = this.filterData.sex.length === 0 ? '' : this.filterData.sex[0];
      const education = this.filterData.education.length === 0 ? '': this.filterData.education[0];
      const domicile = this.filterData.domicile.length === 0 ? '' : this.filterData.domicile[0];
      const workIndustry = this.filterData.workIndustry.length === 0 ? '' : this.filterData.workIndustry[0];
      this.$confirm('确定导出当前查询条件的数据吗','提示').then(()=>{
        const loading=this.$loading({ text: '处理中，请勿关闭页面' })
        exportEnterpriseApi({
          age: age,
          sex: sex,
          education: education,
          domicile: domicile,
          workIndustry: workIndustry,
        }).then((res)=>{
          if(!createFile(res,'问卷调查列表')){
            this.$message.error('未知的文件格式');
          }
        }).finally(()=>{
          loading.close();
        })
      })
    },
    refreshTable() {
      this.tableConf.page = 1
      this.getTableList()
    },
    reset(){
      this.filterData.age = ''
      this.filterData.sex = ''
      this.filterData.education = ''
      this.filterData.domicile = ''
      this.filterData.workIndustry = ''
      this.getTableList()
    }
  }
}
</script>
<style lang="scss" scoped>
.filterData-block {
  .el-form-item {
    margin-bottom: 0;
  }
}
</style>
